package com.itcast.mallapplet.controller.user;

import com.itcast.admin.entity.Seckill;
import com.itcast.applet.dto.SeckillDTO;
import com.itcast.applet.entity.Commodity;
import com.itcast.mallapplet.service.SeckillService;
import com.itcast.result.Result;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.cache.annotation.Cacheable;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/user/seckill")
@Slf4j
@Api(tags = "用户端-秒杀模块")
public class SeckillController {

    @Autowired
    private SeckillService seckillService;

    @GetMapping("/query")
    @ApiOperation("根据id查询单个秒杀商品")
    public Result<Seckill> seckillQuery(Long id) {
        log.info("查询单个秒杀商品的id为：{}", id);
        Seckill seckill = seckillService.seckillQuery(id);
        return Result.success(seckill);
    }

    @GetMapping("/queryAll")
    @ApiOperation("查询全部秒杀商品")
    public Result<List<Seckill>> seckillQueryAll() {
        List<Seckill>  seckillList = seckillService.seckillQueryAll();
        return Result.success(seckillList);
    }

    //1.秒杀商品下单接口，查询全部用户订单窗户

    @PostMapping("/add")
    @ApiOperation("秒杀商品下单")
    public Result seckillAdd(@RequestBody SeckillDTO seckillDTO) {
        log.info("秒杀商品下单信息为: {}",seckillDTO);
        seckillService.seckillAdd(seckillDTO);
        return Result.success();
    }



    

}
